package com.platform.modules.mch.service.impl;

import com.platform.common.utils.Constant;
import com.platform.common.utils.mch.config.MchConfig;
import com.platform.modules.mall.entity.MallGoodsEntity;
import com.platform.modules.mall.entity.MallOrderEntity;
import com.platform.modules.mall.service.MallGoodsService;
import com.platform.modules.mall.service.MallOrderService;
import com.platform.modules.mch.dto.callback.*;
import com.platform.modules.mch.service.MchCallBackService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class MchCallBackServiceImpl implements MchCallBackService {

    @Resource
    private MallGoodsService goodsService;
    @Resource
    private MallOrderService orderService;

    @Override
    public void orderUpdate(MchOrderInfoDto dto) {
        orderService.lambdaUpdate()
                .set(MallOrderEntity::getShippingStatus,dto.getShippingStatus())
                .set(MallOrderEntity::getOrderStatus,dto.getOrderStatus())
                .set(MallOrderEntity::getConfirmTime,dto.getConfirmTime())
//                .set(MallOrderEntity::getRefundTime,dto.getRefundTime())
                .eq(MallOrderEntity::getId,dto.getId())
                .update();
    }

    @Override
    public void goodsIsOnSaleChange(MchGoodsStatusChangeDto dto) {
        goodsService.lambdaUpdate()
                .set(MallGoodsEntity::getIsOnSale,dto.getStatus())
                .eq(MallGoodsEntity::getId,dto.getGoodsId())
                .update();
    }

    @Override
    public void productLocationStatusChange(MchProLocStatusChangeDto dto) {
        if(MchConfig.getLocationId().equals(dto.getLocationId())){
            goodsService.lambdaUpdate()
                    .set(MallGoodsEntity::getIsOnSale,dto.getStatus())
                    .eq(MallGoodsEntity::getId,dto.getGoodsId())
                    .update();
        }
    }

    @Override
    public void cancelAfterVerification(MchVerificationDto dto) {
        orderService.lambdaUpdate()
                .set(MallOrderEntity::getOrderStatus, Constant.OrderStatus.QYHX.getValue())
                .eq(MallOrderEntity::getId,dto.getId())
                .update();
    }

    @Override
    public void orderRefund(MchOrderRefundDto dto) {
        // 暂未启用  退款通知目前使用的订单状态变更
    }

}
